/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} A
 * @param {TreeNode} B
 * @return {boolean}
 */
 var isSubStructure = function(A, B) {
    if(!A || !B){
        return false;
    }
    let res;
    if(A.val==B.val){
        res = issame(A,B);
    }
    return res || isSubStructure(A.left,B) || isSubStructure(A.right,B);
    function issame(A,B){
        if(!B){
            return true;
        }
        if(!A){
            return false;
        }
        if(A.val!=B.val){
            return false;
        }
        return issame(A.left,B.left) && issame(A.right,B.right);
    }
};